<?php

/**
 * ProductImageBackend form.
 *
 * @package    form
 * @subpackage ProductImage
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class ParteCuerpoHumanoImagenBackendForm extends ParteCuerpoHumanoImagenForm 
{
  public function configure()
  {
  	parent::configure();
  	
  	$this->addValidators(array
  	(
  	  'path' => new sfValidatorFile
                (
                  array
                  (
                    'required'   => $this->object->isNew(),
                    'max_size'   => 512000,
                    'mime_types' => 'web_images',
                    'path'       => sfConfig::get('app_parte_cuerpo_humano_images_dir').'/'
                  )
                ),
  	));
  	
    $this->removeWidgets
    (
      array('main')
    );
  }
  
  public function updateObject($values = null)
  {
    if (is_null($values))
    {
      $values = $this->values;
    }
    $file   = $values['path'];
    $values = $this->processValues($values);
    $values = $this->fixValues($values);
    $this->object->fromArray($values);
    
    $this->updateParteCuerpoHumanoImage($file);

    return $this->object;
  }
  
  protected function updateParteCuerpoHumanoImage($file)
  {
  	if ($file)
  	{
      $this->object->setTempPath($this->object->getPath());
    
      if ($this->object->getPath())
      {
        $this->object->createThumbnail(180);
        $this->object->createThumbnail(50);
      }
  	}
  }
}